﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Dzzzr
{
	public class GameEntityInfoList : List<GameEntityInfo>
	{
		public GameEntityInfoList()
		{
		}

		public GameEntityInfoList(IEnumerable<GameEntityInfo> collection) : base(collection)
		{
		}

		public void Normalize()
		{
			Sort();
			int i = 0;
			int? parentID = null;
			foreach (GameEntityInfo entry in this)
			{
				if(entry.ParentID != parentID)
					i = 0;
        entry.OrderNumber = i;
				parentID = entry.ParentID;
				i++;
			}
		}

		public GameEntityInfo FindByEntityID(int entityID)
		{
			return Find(delegate(GameEntityInfo entry) { return entry.EntityID == entityID; });
		}

		public GameEntityInfoList FindLevelByParentEntityID(int? entityID)
		{
			return new GameEntityInfoList(FindAll(delegate(GameEntityInfo entry) { return entry.ParentID == entityID; }));
		}

		
	}
}
